﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME      : FI.Net Application Framework
// COMPONENT ID     : FI.Core.EntLib
// COMPONENT DESC   : Microsoft Enterprise Library Adapter.
//
// CREATED DATE/BY  : 18 Dec 2018 / Tian Mi
//
// REVISION HISTORY :
// DATE/BY            SR#/CS/PM#/OTHERS       DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using System.Configuration;

namespace FI.Core.SettingSource.Configuration
{
    /// <summary>
    /// The <see cref="ConfigurationFileSettingSource"/> specific configuration element.
    /// </summary>
    public class ConfigurationFileSettingSourceData : SettingSourceDataBase
    {
        #region Constants
        private const string FilePathPropertyName = "filePath";
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the file path.
        /// </summary>
        /// <value>
        /// The file path.
        /// </value>
        [ConfigurationProperty(FilePathPropertyName,IsRequired = false, DefaultValue = "")]
        public string FilePath
        {
            get { return (string)base[FilePathPropertyName];}
            set { base[FilePathPropertyName] = value; }
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Creates the setting source.
        /// </summary>
        /// <returns>
        /// The created setting source.
        /// </returns>
        public override ISettingSource CreateSettingSource()
        {
            if (string.IsNullOrEmpty(this.FilePath))
            {
                return new ConfigurationFileSettingSource();
            }
            return new ConfigurationFileSettingSource(this.FilePath);
        }
        #endregion
    }
}
